<?php

use App\Api\AppealController;
use App\Api\AuthController;
use App\Api\CaptchaController;
use App\Api\CarouselController;
use App\Api\ConsultationController;
use App\Api\HomeController;
use App\Api\MenuController;
use App\Api\NoticeController;
use App\Api\PermissionController;
use App\Api\PolicyController;
use App\Api\ReportController;
use App\Api\RoleController;
use App\Api\UploadController;
use App\Api\UserController;
use App\Api\VillageController;
use App\Api\WxuserController;
use Illuminate\Support\Facades\Route;


Route::post('admin/user/login', [AuthController::class, 'login']);
Route::post('admin/user/logout', [AuthController::class, 'logout']);

//登录成功后，系统初始化，通过中间件完成
Route::post('admin/user/info', [UserController::class, 'info'])->middleware('system');

//图形验证码
Route::get('captcha', [CaptchaController::class, 'make']);
//-----------------------后台路由-----------------------
Route::group(['middleware' => ['auth:sanctum']], function () {
    //全局菜单

    Route::post("admin/menus", [MenuController::class, 'generateMenus']);

    Route::post('menu/list', [MenuController::class, 'menuList']);
    Route::post("admin/fullMenu", [MenuController::class, 'fullMenu']);
    //    角色
    //    Route::post('admin/role/init', [RoleController::class, 'init']);
    Route::apiResource('admin/role', RoleController::class);
    Route::post('admin/user/{user}/role', [RoleController::class, 'getRole']);
    Route::post('admin/user/{user}/setRole', [RoleController::class, 'setRole']);
    //    权限（菜单）
    //    Route::post("admin/permission/init", [PermissionController::class, 'initPermissions']);
    Route::post('admin/role/{role}/syncpermissions', [PermissionController::class, 'syncPermissions']);
    Route::post("admin/role/{role}/permissions", [PermissionController::class, "getPermissions"]);
    Route::post('admin/defaultPermission', [PermissionController::class, 'getDefaultPermission']);
    Route::post('admin/user/permissions', [PermissionController::class, 'getUserPermissions']);
    //    用户
    Route::get('user', [UserController::class, 'index']);
    Route::get('admin/user/{user}', [UserController::class, 'show']);
    Route::post('user', [UserController::class, 'store']);
    Route::get('user/{user}', [UserController::class, 'edit']);
    Route::put('user/{user}', [UserController::class, 'update']);
    Route::delete('user/{user}', [UserController::class, 'destroy']);
    Route::post('user/search', [UserController::class, 'searchUser']);
    Route::post('upload/image', [UploadController::class, 'upload']);
    Route::post('upload/wangeditor', [UploadController::class, 'wangeditor']);
    //获取UUID值
    Route::post("admin/home", [HomeController::class, 'index']);

//    consultation 政策咨询
    Route::apiResource('admin/consultation', ConsultationController::class);
    Route::post('admin/consultation/{consultation}/reply', [ConsultationController::class, 'reply']);
    Route::get('admin/consultation/{consultation}/reply', [ConsultationController::class, 'record']);

//    appeal诉求
    Route::apiResource('admin/appeal', AppealController::class);
    Route::post('admin/appeal/{appeal}/reply', [AppealController::class, 'reply']);
    Route::get('admin/appeal/{appeal}/reply', [AppealController::class, 'record']);

//report举报

    Route::apiResource('admin/report', ReportController::class);

    Route::post('admin/report/{report}/reply', [ReportController::class, 'reply']);
    Route::get('admin/report/{report}/reply', [ReportController::class, 'record']);

    //政策
    Route::apiResource('admin/policy', PolicyController::class);
//    轮播图
    Route::apiResource('admin/carousel', CarouselController::class);

    //    公告
    Route::apiResource('admin/notice', NoticeController::class);
    Route::post('admin/notice/{notice}/toggle', [NoticeController::class, 'toggleState']);

    //行政村

    Route::apiResource("admin/village", VillageController::class);
// 行政村设置为管理员
    Route::post("admin/village/{village}/wxuser/{wxuser}/setAdmin", [VillageController::class, 'setAdmin']);
    Route::post("admin/village/{village}/wxuser/{wxuser}/cancelAdmin", [VillageController::class, 'cancelAdmin']);
//    微信用户
    Route::apiResource("admin/wxuser", WxuserController::class);

    //首页统计

    Route::post("admin/statistic", [HomeController::class, "statistic"]);

});

//-----------------------后台路由END-----------------------

//-----------------------前台微信小程序管理路由-----------------------

include(__DIR__.'/mini.php');
